package com.animationsp.acs.servlet;

//import java.io.FileInputStream;
//import java.io.FileNotFoundException;
//import java.io.InputStream;
import java.util.HashMap;
//import java.util.List;
import java.util.Properties;
import java.util.regex.Pattern;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.qiniu.api.config.Config;

//import org.jdom.Document;
//import org.jdom.Element;
//import org.jdom.input.SAXBuilder;

//import com.sun.corba.se.spi.servicecontext.ServiceContext;


public class InitServlet extends HttpServlet {

	public static Properties constant = new Properties();
	
	public static Properties p = new Properties();
	
	public static HashMap appConfig = new HashMap();

	public static HashMap goldIp = new HashMap();

	public static Pattern pt = null;
	
	public static ServletContext servletContext;

	public static String rootPath;

	public void init(ServletConfig config) {
		servletContext = config.getServletContext();
		rootPath = servletContext.getRealPath("/");
		
		// for qiniu AK SK
		Config.ACCESS_KEY = config.getInitParameter("ACCESS_KEY");
		Config.SECRET_KEY = config.getInitParameter("SECRET_KEY");
		// ��ȡϵͳ����constant.properties
//		Constant.reload(config.getServletContext());
//		
//		InputStream in = null;
//			try {
//				in = new FileInputStream(servletContext
//						.getRealPath("/WEB-INF/classes/constant.properties"));
//			Properties p = new Properties();
//			p.load(in);
//			} catch (Exception e) {
//				e.printStackTrace();
//			}
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response) {
		process(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) {
		process(request, response);
	}

	public void process(HttpServletRequest request, HttpServletResponse response) {
		
		// ��ȡ��ϵͳ��Ϣapp.xml
//		String appPath = rootPath + "/WEB-INF/classes/";
//		java.io.File cfgxmlfile = new java.io.File(appPath + "app.xml");
//		try {
//			SAXBuilder builder = new SAXBuilder();
//			Document doc = builder.build(cfgxmlfile);
//			Element root = doc.getRootElement();
//			List apps = root.getChildren();
//			for (int i = 0; i < apps.size(); i++) {
//				App app = new App();
//				Element ele = (Element) apps.get(i);
//				int id = ele.getAttribute("id").getIntValue();
//				String name = ele.getAttribute("name").getValue();
//				String url = ele.getAttribute("url").getValue();
//				app.setId(id);
//				app.setName(name);
//				app.setUrl(url);
//				appConfig.put(new Integer(id), app);
//			}
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//		goldIp.clear();
//		List ips = UserDAO.getAllGoldIp();
//		for (int i = 0; i < ips.size(); i++) {
//			goldIp.put(ips.get(i), "1");
//		}
//
//		String type = request.getParameter("type");
//		System.out.println(type);
//		if (type != null) {
//			List list = ActiveDao.findAllGold();
//			for (int i = 0; i < list.size(); i++) {
//				User user = (User) list.get(i);
//				Constant.genGoldJs(user);
//			}
//		}
	}
}
